package com.mingqijia.gassafety.shared.vcc;

import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * VCC授权配置
 * @author Damon S.
 * @version v1.0.1
 * @date 2020年07月12日 15:45
 */
@Data
@Component
@Slf4j
@ConfigurationProperties(prefix = "vcc.open-code")
public class VccTokenCodeConfig {
    @JsonIgnore
    private String server;
    private String grantType;
    private String code;
    private String scope;
    private String openAppId;
    private String openAppSecret;
    private String redirectUri;
    private String refreshToken;
    // h5页面的token
    private String h5Token;


    private static final String TEMPLATE_AUTHORIZE = "%s/oauth/authorize";
    private static final String TEMPLATE_TOKEN = "%s/open-auth/oauth2/token";
    private static final String TEMPLATE_TOKEN_CHECK = "%s/open-auth/oauth2/token/check";
    private static final String TEMPLATE_REFRESH = "%s/open-auth/oauth2/token/refresh";

    public String getGenTokenUrl(String client) {
//        if (client.equals(vccOathConfig.getClientIdIp())){
//            log.info("授权跳转的地址:{}",String.format(TEMPLATE_TOKEN, vccOathConfig.getServerIp()));
//            return String.format(TEMPLATE_TOKEN, vccOathConfig.getServerIp());
//        }
        return String.format(TEMPLATE_TOKEN, server);
    }

    public String getRefreshTokenUrl() {
        return String.format(TEMPLATE_REFRESH, server);
    }

    public String getCheckTokenUrl() {
        return String.format(TEMPLATE_TOKEN_CHECK, server);
    }

    public String toJson() {
        return JSONUtil.toJsonStr(this);
    }
}


